//
//  ZZPopMenuItem.m
//  ZZPopMenu
//
//  Created by 科大 on 2024/3/1.
//

#import "ZZPopMenuItem.h"

@implementation ZZPopMenuItem

+ (instancetype)itemWithTitle:(NSString *)title {
    return [self itemWithTitle:title imageName:@"" color:[UIColor whiteColor] font:[UIFont systemFontOfSize:14] direction:ZZItemDirectionHorizontal];
}

+ (instancetype)itemWithTitle:(NSString *)title imageName:(NSString *)imageName {
    return [self itemWithTitle:title imageName:imageName color:[UIColor whiteColor] font:[UIFont systemFontOfSize:14] direction:ZZItemDirectionHorizontal];
}

+ (instancetype)itemWithTitle:(NSString *)title imageName:(NSString *)imageName color:(UIColor *)color {
    return [self itemWithTitle:title imageName:imageName color:color font:[UIFont systemFontOfSize:14] direction:ZZItemDirectionHorizontal];
}

+ (instancetype)itemWithTitle:(NSString *)title imageName:(NSString *)imageName color:(UIColor *)color font:(UIFont *)font {
    return [self itemWithTitle:title imageName:imageName color:color font:font direction:ZZItemDirectionHorizontal];
}

+ (instancetype)itemWithTitle:(NSString *)title imageName:(NSString *)imageName color:(UIColor *)color font:(UIFont *)font direction:(ZZItemDirection)direction {
    ZZPopMenuItem *item = [[ZZPopMenuItem alloc] init];
    item.title = title;
    item.imageName = imageName;
    item.color = color;
    item.font = font;
    item.direction = direction;
    return item;
}

- (CGSize)itemSize {
    CGSize size = CGSizeMake(MAXFLOAT, self.font.pointSize);
    NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:self.font.pointSize], NSFontAttributeName, nil];
    CGRect rect = [self.title boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil];
    if (self.imageName.length > 0) {
        return CGSizeMake(ceil(rect.size.width) + 30, ZLLineHeight);
    }
    return CGSizeMake(ceil(rect.size.width), ZLLineHeight);
}

@end
